//
//  MainViewController.swift
//  weibo22
//
//  Created by keshuaiguo on 16/1/17.
//  Copyright © 2016年 keshuaiguo. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    //MARK:按钮的监听事件
    func PlusBtnDidClick() {
    
        print(__FUNCTION__)
    
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        //可以使用kvc 间接修改 
//        print(tabBar.classForCoder)

        let mainTabBar = MainTabbar()
        
        setValue(mainTabBar, forKey: "tabBar")

//        print(tabBar.classForCoder)
        
        //加号按钮的事件
        mainTabBar.plusBtn.addTarget(self, action: "PlusBtnDidClick", forControlEvents: .TouchUpInside)

        addChildViewControllers()
    }

    
    private func addChildViewControllers() {
        //首页
        addChildViewController(HomeTableViewController(), imageName: "tabbar_home", title: "首页")
        //消息
        addChildViewController(MessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        //发现
        addChildViewController(DiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        //我
        addChildViewController(ProfileTableViewController(), imageName: "tabbar_profile", title: "我")
    }
    ///添加子视图控制器
   private func addChildViewController(vc: UIViewController,imageName: String,title: String) {
        //实例化 VC
        //设置图片
        vc.tabBarItem.image = UIImage(named: imageName)
        //设置item选中的图片 //手写代码修改图片显示样式
        self.tabBar.tintColor = UIColor.orangeColor()
        //        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(.AlwaysOriginal)
        //        //
        //        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        
        //设置title
        //        home.tabBarItem.title = "首页"_highlighted
        //        home.navigationItem.title = "首页"
        vc.title = title
        
        //导航控制器
        let nav = UINavigationController(rootViewController: vc)
        
        
        //添加子视图控制器
        addChildViewController(nav)
    }
    

}
